package com.flurry.android;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import android.util.Log;
import com.flurry.android.caching.ObjectData;
import java.util.ArrayList;

public abstract class CacheDBOperations extends al
{
  protected String TAG;

  public void addItem(bm parambm)
  {
    Log.d(this.TAG, "--- Insert in " + this.cE + " : ---");
    SQLiteDatabase localSQLiteDatabase = this.cD.getWritableDatabase();
    ContentValues localContentValues = new ContentValues();
    String str1 = parambm.dE;
    String str2 = parambm.dF;
    String str3 = parambm.dG;
    String str4 = parambm.dC;
    String str5 = parambm.dD;
    localContentValues.put("objectsId", str1);
    localContentValues.put("timestamp", Long.valueOf(System.currentTimeMillis()));
    localContentValues.put("objectsLocalId", str2);
    localContentValues.put("collectionName", str3);
    localContentValues.put("key", str4);
    localContentValues.put("value", str5);
    localSQLiteDatabase.insert(this.cE, null, localContentValues);
  }

  final void c(String paramString1, String paramString2, String paramString3)
  {
    Cursor localCursor = this.cD.getWritableDatabase().query(this.cE, null, "objectsId='" + paramString3 + "'", null, null, null, "objectsId ASC, julianday(timestamp)");
    if (localCursor.moveToFirst())
    {
      int i = localCursor.getColumnIndex("primery_key_id");
      int j = localCursor.getColumnIndex("key");
      int k = localCursor.getColumnIndex("value");
      int m = localCursor.getInt(i);
      String str1 = localCursor.getString(j);
      String str2 = localCursor.getString(k);
      if ((!str1.equals(paramString1)) || (!str2.equals(paramString2)))
        break label195;
      e(m);
      Log.e(this.TAG, "removed as not modified (key, value) = ( " + paramString1 + " ; " + paramString2 + " );");
    }
    while (true)
    {
      localCursor.close();
      return;
      label195: if (localCursor.moveToNext())
        break;
    }
  }

  final void e(int paramInt)
  {
    this.cD.getWritableDatabase().delete(this.cE, "primery_key_id='" + paramInt + "'", null);
  }

  public ArrayList<bm> getData()
  {
    ArrayList localArrayList = new ArrayList();
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, null, null, null, null, "objectsId ASC, julianday(timestamp)");
    if (localCursor.moveToFirst())
    {
      int i = localCursor.getColumnIndex("objectsId");
      int j = localCursor.getColumnIndex("objectsLocalId");
      int k = localCursor.getColumnIndex("collectionName");
      int m = localCursor.getColumnIndex("key");
      int n = localCursor.getColumnIndex("value");
      do
        localArrayList.add(new bm(localCursor.getString(m), localCursor.getString(n), localCursor.getString(i), localCursor.getString(j), localCursor.getString(k)));
      while (localCursor.moveToNext());
    }
    while (true)
    {
      localCursor.close();
      return localArrayList;
      Log.w(this.TAG, "TABLE " + this.cE + " IS EMPTY");
    }
  }

  abstract ObjectData getObjectById(String paramString);

  public String getValueByKey(String paramString1, String paramString2, String paramString3)
  {
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, "objectsId='" + paramString2 + "'", null, null, null, "objectsId ASC, julianday(timestamp)");
    boolean bool = localCursor.moveToFirst();
    String str1 = null;
    int j;
    String str2;
    String str3;
    if (bool)
    {
      int i = localCursor.getColumnIndex("key");
      j = localCursor.getColumnIndex("value");
      int k = localCursor.getColumnIndex("collectionName");
      str2 = localCursor.getString(k);
      str3 = localCursor.getString(i);
      if ((TextUtils.isEmpty(str2)) || (!str2.equals(paramString3)) || (!str3.equals(paramString1)))
        break label165;
      str1 = localCursor.getString(j);
    }
    while (true)
    {
      localCursor.close();
      return str1;
      label165: if ((TextUtils.isEmpty(str2)) && (TextUtils.isEmpty(paramString3)) && (str3.equals(paramString1)))
      {
        str1 = localCursor.getString(j);
      }
      else
      {
        if (localCursor.moveToNext())
          break;
        str1 = null;
      }
    }
  }

  public boolean hasKey(String paramString)
  {
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, "key='" + paramString + "'", null, null, null, "objectsId ASC, julianday(timestamp)");
    if (localCursor.moveToFirst());
    for (boolean bool = true; ; bool = false)
    {
      localCursor.close();
      return bool;
    }
  }

  public boolean hasKeyValueObject(bm parambm)
  {
    String str1 = parambm.dE;
    String str2 = parambm.dC;
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, "key='" + str2 + "'", null, null, null, "objectsId ASC, julianday(timestamp)");
    if (localCursor.moveToFirst())
    {
      int i = localCursor.getColumnIndex("objectsId");
      if (!localCursor.getString(i).equals(str1));
    }
    for (boolean bool = true; ; bool = false)
    {
      localCursor.close();
      return bool;
      if (localCursor.moveToNext())
        break;
    }
  }

  public boolean isUserObject(String paramString)
  {
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, "objectsId='" + paramString + "'", null, null, null, "objectsId ASC, julianday(timestamp)");
    boolean bool;
    if (localCursor.moveToFirst())
    {
      int i = localCursor.getColumnIndex("collectionName");
      if (TextUtils.isEmpty(localCursor.getString(i)))
      {
        bool = true;
        label80: if (localCursor.moveToNext())
          break label100;
      }
    }
    while (true)
    {
      localCursor.close();
      return bool;
      bool = false;
      break label80;
      label100: break;
      bool = false;
    }
  }

  public void readAll()
  {
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, null, null, null, null, "objectsId ASC, julianday(timestamp)");
    if (localCursor.moveToFirst())
    {
      int i = localCursor.getColumnIndex("primery_key_id");
      int j = localCursor.getColumnIndex("timestamp");
      int k = localCursor.getColumnIndex("objectsId");
      int m = localCursor.getColumnIndex("objectsLocalId");
      int n = localCursor.getColumnIndex("collectionName");
      int i1 = localCursor.getColumnIndex("key");
      int i2 = localCursor.getColumnIndex("value");
      do
        Log.w(this.TAG, "ID = " + localCursor.getInt(i) + ", timestamp = " + localCursor.getLong(j) + ", id = " + localCursor.getString(k) + ", local_id = " + localCursor.getString(m) + ", collection_name = " + localCursor.getString(n) + ", key = " + localCursor.getString(i1) + ", value = " + localCursor.getString(i2));
      while (localCursor.moveToNext());
    }
    while (true)
    {
      localCursor.close();
      return;
      Log.w(this.TAG, "TABLE " + this.cE + " IS EMPTY");
    }
  }

  public void updateItem(String paramString1, String paramString2, String paramString3, String paramString4)
  {
    Log.d(this.TAG, "--- update item in " + this.cE + ": ---");
    Cursor localCursor = this.cD.getReadableDatabase().query(this.cE, null, "objectsId='" + paramString3 + "'", null, null, null, "objectsId ASC, julianday(timestamp)");
    if (localCursor.moveToFirst())
    {
      int j = localCursor.getColumnIndex("primery_key_id");
      int k = localCursor.getColumnIndex("key");
      int m = localCursor.getInt(j);
      if (localCursor.getString(k).equals(paramString1))
      {
        SQLiteDatabase localSQLiteDatabase = this.cD.getWritableDatabase();
        ContentValues localContentValues = new ContentValues();
        localContentValues.put("objectsId", paramString3);
        localContentValues.put("objectsLocalId", null);
        localContentValues.put("timestamp", Long.valueOf(System.currentTimeMillis()));
        localContentValues.put("collectionName", paramString4);
        localContentValues.put("key", paramString1);
        localContentValues.put("value", paramString2);
        localSQLiteDatabase.update(this.cE, localContentValues, "primery_key_id='" + m + "'", null);
      }
    }
    for (int i = 1; ; i = 0)
    {
      if (i == 0)
        addItem(new bm(paramString1, paramString2, paramString3, null, paramString4));
      localCursor.close();
      return;
      if (localCursor.moveToNext())
        break;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.flurry.android.CacheDBOperations
 * JD-Core Version:    0.6.2
 */